<?php

namespace App\Model\WMS;

use App\Model\Base;

class Warehouse extends Base
{

	const NAME = '仓库';

	protected $table = 'wms_warehouse';
	public $timestamps = false;

	protected $fillable = [
		'name' => 'name',
		'type' => 'type',
		'country' => 'country',
		'province' => 'province',
		'city' => 'city',
		'addr' => 'addr',
		'postcode' => 'postcode',
		'tel' => 'tel',
		'manager' => 'manager',
		'phone' => 'phone',
		'is_on' => 'is_on',
	];


	protected static $translation = [
	    'type' => [
	        1 => '自有仓库',
	        2 => 'FBA',
	        3 => 'TWUsa',
            4 => '3PL',
        ]
    ];

	protected $casts = [
		'is_on' => 'boolean'
	];







	/**
	 * 检测·名称是否有效
	 * @return true|null
	 * */
	public function isNameValid ()
	{
		return $this->name ? true : self::debug(self::NAME.'名称未填写。');
	}


    /**
     * 检测·国家字段
     * @return true|null
     * */
    public function isCountryValid ()
    {
        return $this->country ? true : self::debug(self::NAME.'国家未设置。');
    }



    /**
     * 检测·类型是否有效
     * @return true|null
     * */
    public function isTypeValid ()
    {
        return @self::$translation[$this->type] ? true : self::debug(self::NAME.'类型未知。');
    }


	public function scopeWhereOn ($query, $status=true)
	{
		return $query->where('is_on', $status ? 1 : 0);
	}







}